package ${basePackage}.controller;
import ${basePackage}.model.${modelNameUpperCamel};
import ${basePackage}.service.${modelNameUpperCamel}Service;
import com.company.project.core.MsgMap;
import com.company.project.core.BaseController;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;

/**
* Created by ${author} on ${date}.
*/
@Controller
@RequestMapping("/${modelNameLowerCamel}")
public class ${modelNameUpperCamel}Controller extends BaseController{

    @Autowired
    private ${modelNameUpperCamel}Service ${modelNameLowerCamel}Service;

    @RequestMapping("add")
    @ResponseBody
    public MsgMap add(${modelNameUpperCamel} ${modelNameLowerCamel}) {
        MsgMap msg = this.getMsgMap();
        ${modelNameLowerCamel}Service.save(${modelNameLowerCamel});
        return msg;
    }

    @RequestMapping("delete")
    @ResponseBody
    public MsgMap delete(${modelNameUpperCamel} ${modelNameLowerCamel}) {
        MsgMap msg = this.getMsgMap();
        ${modelNameLowerCamel}Service.deleteById(${modelNameLowerCamel});
        return msg;
    }

    @RequestMapping("update")
    @ResponseBody
    public MsgMap update(${modelNameUpperCamel} ${modelNameLowerCamel}) {
        MsgMap msg = this.getMsgMap();
        ${modelNameLowerCamel}Service.update(${modelNameLowerCamel});
        return msg;
    }

    @RequestMapping("detail")
    @ResponseBody
    public MsgMap detail(${modelNameUpperCamel} ${modelNameLowerCamel}) {
        MsgMap msg = this.getMsgMap();
        ${modelNameUpperCamel} ${modelNameLowerCamel}Result = ${modelNameLowerCamel}Service.findById(${modelNameLowerCamel});
        return msg;
    }

    @RequestMapping("list")
    @ResponseBody
    public MsgMap list(${modelNameUpperCamel} ${modelNameLowerCamel} , @RequestParam(defaultValue = "0") Integer page
                        , @RequestParam(defaultValue = "10") Integer size) {
        MsgMap msg = this.getMsgMap();
        List<${modelNameUpperCamel}> list = ${modelNameLowerCamel}Service.list( ${modelNameLowerCamel} , page , size  );
        PageInfo pageInfo = new PageInfo(list);
        return msg;
    }
}
